#include <iostream>
#include <string>
#include <memory>
#include <functional>
#include "IDLLoader.h"
#include "IPlanet.h"

using namespace std;

#ifdef WIN32
static const std::string bespinLibPath = "Bespin.dll";
static const std::string tatooineLibPath = "Tatooine.dll";
#endif
#ifdef __linux__
static const std::string bespinLibPath = "./libBespin.so";
static const std::string tatooineLibPath = "./libTatooine.so";
#endif
#ifdef __APPLE__
static const std::string bespinLibPath = "./libBespin.dylib";
static const std::string tatooineLibPath = "./libTatooine.dylib";
#endif

int main()
{
    //创建并加载库
    std::shared_ptr<dlloader::IDLLoader> dllLoader_tatooine = dlloader::IDLLoader::create();
    dllLoader_tatooine->openLib(tatooineLibPath);

    //类调用
    std::shared_ptr<IPlanet> planet_tatooine = dllLoader_tatooine->getClassInstance<IPlanet>();
    planet_tatooine->greet();
    
    /********************************************************************************************************************/
    //创建并加载库
    std::shared_ptr<dlloader::IDLLoader> dllLoader_bespin = dlloader::IDLLoader::create();
    dllLoader_bespin->openLib(bespinLibPath);

    //类调用
    std::shared_ptr<IPlanet> planet_bespin = dllLoader_bespin->getClassInstance<IPlanet>();
    planet_bespin->greet();

    //函数调用
    std::shared_ptr<int32_t(int32_t, int32_t)> add = dllLoader_bespin->getFuncInstance<int32_t(int32_t, int32_t)>("add_integers");
    std::cout << add.get()(1, 2) << std::endl;

    return 0;
}